package me.caofeng.controller;

import me.caofeng.enums.Role;
import me.caofeng.pojo.Category;
import me.caofeng.pojo.Response;
import me.caofeng.service.api.ICategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Copyright © 2017曹峰. All rights reserved.
 *
 * @Prject: mall
 * @Package: me.caofeng.controller
 * @Description:
 * @Author: 曹峰 blog.caofeng.me
 * @Date: 2017-06-25 11:31
 * @Version: V1.0
 */
@Controller
@RequestMapping(value = "category")
public class CategoryController {
    @Autowired
    private ICategoryService categoryService;

    @RequestMapping(value = "{id}", method = RequestMethod.GET)
    @ResponseBody
    public Response<List<Category>> getCategory(
            @PathVariable(value = "id") Integer id,
            @RequestParam(value = "status", required = false) Integer status) {
        Response<List<Category>> response = categoryService.getCategories(id, status, Role.MEMBER);
        return response;
    }

    /**
     * @Author:曹峰 blog.caofeng.me
     * @Date: 2017/6/19 23:44
     * @Description: 获取分类详情
     */
    @RequestMapping(value = "{parentId}/{id}", method = RequestMethod.GET)
    @ResponseBody
    public Response<Category> getCategory(@PathVariable("parentId") Integer parentId,
                                          @PathVariable("id") Integer id,
                                          @RequestParam(value = "status", required = false) Integer status) {
        return categoryService.getCategory(parentId, id, status, Role.MEMBER);
    }

}
